<template>
  <section>
    <div class="flex-row">
      <div class="flex-item-fixed mr10">
        <div class="preview-layer">
          <div class="preview-bg"></div>
          <div class="preview-phone">
            <div class="preview-content">
              <div class="top-video">

                <video-player  class="video-player-box"
                               ref="videoPlayer"
                               :options="playerOptions"
                               :playsinline="true"
                               @ready="playerReadied" v-if="currentNews.video">
                </video-player>
                <!--<template v-else>-->
                  <!--<image-cover v-if="currentNews.cover1" :thumb.sync="currentNews.cover1" width="361px" height="241px" size-type="contain"></image-cover>-->
                <!--</template>-->
              </div>

              <div class="article-title">
                <h1 class="title">{{currentNews.title}}</h1>
              </div>
              <div class="article-provide">
                  <span>{{currentNews.source}}</span>
              </div>
              <div class="article-content">
                <html-content :contentHtml="currentNews.content"></html-content>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="flex-item-fixed preview-right">
        <el-col class="pd5" v-if="currentNews.status===0||currentNews.status===2">
          <el-button type="info" plain @click="save(1)">发布</el-button>
        </el-col>
        <el-col class="pd5" v-if="currentNews.status===1">
          <el-button type="danger" plain @click="save(2)">下架</el-button>
        </el-col>
      </div>
    </div>
  </section>
</template>

<script>
import { mapGetters } from "vuex";
import ImageCover from "@/components/image-cover";
import HtmlContent from "@/components/html-content";
export default {
  name: "pre-news",
  props: {
    isClose: Boolean
  },
  created() {},
  mounted() {
    this.$watch("currentNews", val => {
      if (val) {
        this.updateVideo();
      }
    });
  },
  computed: {
    ...mapGetters({
      currentNews: "currentNews",
      playerOptions: "playerOptions"
    })
  },
  data() {
    return {};
  },
  methods: {
    // player is ready
    playerReadied(player) {
      var obj = {};
      obj.poster = this.$options.filters.fullImagePath(this.currentNews.cover1);
      obj.src = this.$options.filters.fullImagePath(this.currentNews.video);
      console.log(obj);
      this.$store.dispatch("updateVideoOptions", obj).then(ret => {
        console.log(this.currentNews);
      });
    },
    updateVideo() {
      var obj = {};
      obj.poster = this.$options.filters.fullImagePath(this.currentNews.cover1);
      obj.src = this.$options.filters.fullImagePath(this.currentNews.video);
      console.log(obj);
      this.$store.dispatch("updateVideoOptions", obj).then(ret => {
        console.log(this.currentNews);
      });
    },
    back() {
      this.$emit("close");
    },
    save(status) {
      this.currentNews.status = status;
      this.$store.dispatch("addOrUpdateNewsS", this.currentNews).then(ret => {
        this.$notify({
          title: "提交成功",
          type: "success"
        });
        this.back();
      });
    }
  },
  components: {
    ImageCover,
    HtmlContent
  }
};
</script>

<style scoped>
@import "../../../../src/styles/preview-style.css";
</style>
